#!/usr/bin/env bash

if (( $# < 3 ))
then
    echo "Usage:   $(basename $0) {table_template} {begin_month} {end_month}"
    echo "Example: $(basename $0) user_log 201001 201010"
    exit
fi

template=$1
begin=$2
end=$3
curr=$begin
curr_date=${begin}01
while [[ $curr -le $end ]]
do
    cat <<EOF
create table ${template}_${curr} like ${template};
alter table ${template}_${curr} auto_increment=${curr}00000001;

EOF
    curr_date=$(date -d "$curr_date 1 month" "+%Y%m%d")
    curr=${curr_date:0:6}
done
